<!--撤回案件-->

<template>
  <el-dialog title="撤回投诉举报案件" width="60%" :visible="visible" @close="handleClose">
    <div class="white-card">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="撤回原因：" prop="reason">
          <el-input v-model="form.reason" show-word-limit maxlength="300" placeholder="请输入详细描述" type="textarea" style="width: 100%; height: 150px"></el-input>
        </el-form-item>
        <el-form-item label="撤回类型：" prop="revokeType">
          <el-select v-model="form.revokeType">
            <el-option v-for="item in returnTypeDictList" :key="item.id" :label="item.name" :value="item.name">{{ item.name }}</el-option>
          </el-select>
        </el-form-item>

        <div class="dialog-footer-btn">
          <el-button @click="handleClose" type="primary" plain>关闭</el-button>
          <el-button @click="handleSubmit" :loading="submitting" type="primary">确定</el-button>
        </div>
      </el-form>
    </div>
  </el-dialog>
</template>

<script>
import * as mixins from "@/utils/mixins";
import * as portalWorkOrderAPI from "@/api/portals/workOrder";
import { getCMSUserInfo } from "@/utils/common";
import * as dictApi from "@/api/dict";

export default {
  name: "recallDialog",
  mixins: [mixins.dialog, mixins.form],
  props: ["visible", "workOrderId"],
  data() {
    return {
      form: {
        reason: "",
        revokeType: "",
      },
      rules: {
        reason: [{ required: true, message: "请填写" }],
        revokeType: [{ required: true, message: "请选择" }],
      },
      optionList: [],
      returnTypeDictList: [],
      submitting: false,
    };
  },
  created() {
    this.getDictList();
  },
  methods: {
    show() {},
    getDictList() {
      dictApi
        .list({ parentCode: "1008" })
        .then((res) => {
          this.returnTypeDictList = res.result;
        })
        .finally(() => {});
    },
    handleSubmit() {
      this.validate("form")
        .then(() => {
          const cmsUserInfo = getCMSUserInfo();
          console.log("cmsUserInfo :>> ", cmsUserInfo);
          this.submitting = true;
          return portalWorkOrderAPI.revoke({
            ...this.form,
            accountId: cmsUserInfo.userId,
            name: decodeURIComponent(cmsUserInfo.userName),
            workOrderId: this.workOrderId,
          });
        })
        .then(() => {
          this.$emit("success");
          this.handleClose();
          this.$alert("撤回提交成功，请等待相关主管单位审批通过。", "提示", { customClass: "top20" });
        })
        .finally(() => {
          this.submitting = false;
        });
    },
  },
};
</script>

<style scoped>
.el-select {
  width: 100%;
}
</style>
